#ifndef __IIC_H
#define __IIC_H
#include "sys.h"

#define     IIC_STATE_ERROR     2U
#define     IIC_STATE_OK        1U
#define     IIC_STATE_FALSE     0U

#define     IIC_SDA_GPIO        GPIOB
#define     IIC_SDA_PIN         GPIO_PIN_7
#define     IIC_SDA_RCC_INIT()  __HAL_RCC_GPIOB_CLK_ENABLE()
#define     IIC_SDA_Tx(x)       do{ \
                                    x ? \
                                    HAL_GPIO_WritePin(IIC_SDA_GPIO, IIC_SDA_PIN, GPIO_PIN_SET) : \
                                    HAL_GPIO_WritePin(IIC_SDA_GPIO, IIC_SDA_PIN, GPIO_PIN_RESET); \
                                    } while(0U)
#define     IIC_SDA_Rx          HAL_GPIO_ReadPin(IIC_SDA_GPIO, IIC_SDA_PIN)

#define     IIC_SCL_GPIO        GPIOB
#define     IIC_SCL_PIN         GPIO_PIN_6
#define     IIC_SCL_RCC_INIT()  __HAL_RCC_GPIOB_CLK_ENABLE()
#define     IIC_SCL_Tx(x)       do{ \
                                    x ? \
                                    HAL_GPIO_WritePin(IIC_SCL_GPIO, IIC_SCL_PIN, GPIO_PIN_SET) : \
                                    HAL_GPIO_WritePin(IIC_SCL_GPIO, IIC_SCL_PIN, GPIO_PIN_RESET); \
                                    } while(0U)


void iic_init(void);
void iic_start(void);
void iic_stop(void);
uint8_t iic_wait_ack(void);
void iic_write_byte(uint8_t data);
uint8_t iic_read_byte(void);


#endif


